/**
 * @program: clms-second
 * @description:
 * @author: mitu_echo
 * @create: 2021-07-26 14:15
 **/

package com.second.system.service.impl;

import com.second.system.dao.LogininfoDao;
import com.second.system.pojo.entity.Logininfo;
import com.second.system.pojo.utils.WebUtil;
import com.second.system.service.LogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class LogininfoServiceImpl implements LogininfoService {

    @Autowired
    private LogininfoDao logininfoDao;

    @Override
    public void addLogininfo(String loginname,String ipaddr,Character status) {

        Logininfo logininfo = new Logininfo();
        logininfo.setStatus(status);
        if (status == '0') {
            logininfo.setMsg("登录成功");
        } else {
            logininfo.setMsg("登录失败，密码或用户名错误");
        }
        logininfo.setLoginName(loginname);
        logininfo.setIpaddr(ipaddr);
        logininfo.setLoginLocation("内网ip");
        logininfo.setLoginTime(LocalDateTime.now().toString());
        String browser = WebUtil.getRequest().getHeader("User-Agent");
        if (browser.indexOf("Firefox") >0 ) {
            logininfo.setBrowser("Firefox");
        }
        if (browser.indexOf("Chrome") >0 ) {
            logininfo.setBrowser("Chrome");
        }
        if (browser.indexOf("MSIE") > 0) {
            logininfo.setBrowser("ie");
        }
        if (browser.indexOf("Windows NT 10.0") >0 ) {
            logininfo.setOs("Win10");
        }
        if (browser.indexOf("Windows NT 6.1") >0 ) {
            logininfo.setOs("Win7");
        }
        logininfoDao.insert(logininfo);
    }
}
